import http from './http'

export interface DeliverySearchParams {
  shipment_no?: string
  customer?: string
  status?: string
  start_date?: string
  end_date?: string
  page?: number
  pageSize?: number
}

export interface DeliveryForm {
  delivery_date: string
  delivery_address: string
  delivery_contact: string
  delivery_phone: string
  warehouse: string
  packager?: string
  shipper?: string
  shipping_method: string
  freight: number
  tax_rate: number
  discount: number
}

export interface OutboundForm {
  outbound_date: string
  operator: string
  notes?: string
}

export interface ShipmentForm {
  ship_date: string
  tracking_no: string
  carrier: string
  shipper: string
  notes?: string
}

export const deliveryApi = {
  // 获取送货单列表
  getList: (params?: DeliverySearchParams) => http.get('/deliveries', { params }),

  // 获取送货单详情
  getDetail: (id: number) => http.get(`/deliveries/${id}`),

  // 打印送货单
  print: (id: number) => http.get(`/deliveries/${id}/print`),

  // 批量打印送货单
  batchPrint: (orderIds: number[]) => http.post('/deliveries/batch/print', { order_ids: orderIds }),

  // 获取送货单统计
  getStats: () => http.get('/deliveries/stats'),

  // 导出送货单数据
  export: (params: DeliverySearchParams) => http.get('/deliveries/export', { params, responseType: 'blob' }),

  // 重新生成送货单号
  regenerateShipmentNo: (id: number) => http.put(`/deliveries/${id}/regenerate`),

  // 确认出库
  confirmOutbound: (id: number, data: OutboundForm) => http.put(`/orders/${id}/outbound`, data),

  // 确认发货
  confirmShipment: (id: number, data: ShipmentForm) => http.put(`/orders/${id}/ship`, data)
} 